﻿import QtQuick 2.0

Item {
    id: role;
    property int id: -1;
    property string name: "DefName";
    property double blood: 1.0;
    property bool isCur: false;
    property rect itemRect: Qt.rect(0,0,width,height);
    
    property int targetX: 0;
    property int targetY: 0;
    property int speedDis: 10; //每speedDur走10px
    property int speedDur: 45; //每45ms走speed
    
    //
    property rect coreRect: Qt.rect(0,0,width,height);
     
    
    function setPosition(x,y){
        targetX = x - coreRect.width/2 - coreRect.x;
        targetY = y - coreRect.height/2 - coreRect.y;
        startWalkTask();
    }
    
    function startWalkTask(){
        var maxV = Math.max(Math.abs(x-targetX),Math.abs(y-targetY));
        var dur = maxV / speedDis * speedDur;
        xAni.duration = dur;
        yAni.duration = dur;
        
        xAni.restart();
        yAni.restart();
    }
    
    function createRanName(){
        var lNames = [qsTr("龙"),qsTr("独孤"),qsTr("长孙"),qsTr("慕容"),qsTr("宇文"),qsTr("欧阳"),qsTr("诸葛")];
        var f1Names = [qsTr("傲"),qsTr("轩"),qsTr("良"),qsTr("霸"),qsTr("浩"),qsTr("哲"),qsTr("鲲"),qsTr("轮")];
        var f2Names = [qsTr("天"),qsTr("辕"),qsTr("辰"),qsTr("世"),qsTr("劫"),qsTr("彦"),qsTr("鹏"),qsTr("回")];
        name = lNames[parseInt(Math.random()*10000)%lNames.length] 
                + f1Names[parseInt(Math.random()*10000)%f1Names.length] 
                + f2Names[parseInt(Math.random()*10000)%f2Names.length];
    }
    
    NumberAnimation {
        id: xAni;
        target: role
        to: targetX
        property: "x"
        easing.type: Easing.Linear
    }
    
    NumberAnimation {
        id: yAni;
        target: role
        to: targetY
        property: "y"
        easing.type: Easing.Linear
    }
    
}
